package jym.tan.movielibrary.factory;

import java.util.ArrayList;

import javax.swing.table.TableModel;

import jym.tan.movielibrary.component.ui.button.AddSingleFolderButton;
import jym.tan.movielibrary.component.ui.button.MovieTitleConfirmButton;
import jym.tan.movielibrary.component.ui.button.SingleMovieAddButton;
import jym.tan.movielibrary.component.ui.combobox.ThemeComboBox;
import jym.tan.movielibrary.component.ui.dialog.MovieTitleConfirmDialog;
import jym.tan.movielibrary.component.ui.dialog.SingleMovieAddDialog;
import jym.tan.movielibrary.component.ui.filechooser.SingleFolderChooser;
import jym.tan.movielibrary.component.ui.frame.LibraryFrame;
import jym.tan.movielibrary.component.ui.label.FolderPathLabel;
import jym.tan.movielibrary.component.ui.label.IMDbLogoLabel;
import jym.tan.movielibrary.component.ui.label.MovieSearchNameLabel;
import jym.tan.movielibrary.component.ui.label.MovieSearchPosterLabel;
import jym.tan.movielibrary.component.ui.label.MovieSearchYearLabel;
import jym.tan.movielibrary.component.ui.menu.FileMenu;
import jym.tan.movielibrary.component.ui.menu.bar.DefaultMenuBar;
import jym.tan.movielibrary.component.ui.menu.item.RestartMenuItem;
import jym.tan.movielibrary.component.ui.menu.item.SingleMovieAddMenuItem;
import jym.tan.movielibrary.component.ui.panel.AddSingleFolderButtonOuterPanel;
import jym.tan.movielibrary.component.ui.panel.AddSingleFolderTextFieldOuterPanel;
import jym.tan.movielibrary.component.ui.panel.DefaultToolbarPanel;
import jym.tan.movielibrary.component.ui.panel.LibraryTablePanel;
import jym.tan.movielibrary.component.ui.panel.MovieSearchInfoPanel;
import jym.tan.movielibrary.component.ui.panel.MovieSearchResultPanel;
import jym.tan.movielibrary.component.ui.panel.MovieTitleConfirmPanel;
import jym.tan.movielibrary.component.ui.panel.SingleMovieAddLowerLeftPanel;
import jym.tan.movielibrary.component.ui.panel.SingleMovieAddLowerRightPanel;
import jym.tan.movielibrary.component.ui.panel.SingleMovieAddPanel;
import jym.tan.movielibrary.component.ui.panel.SingleMovieAddUpperPanel;
import jym.tan.movielibrary.component.ui.scrollpane.LibraryTableScrollPane;
import jym.tan.movielibrary.component.ui.scrollpane.MovieSearchInfoScrollPane;
import jym.tan.movielibrary.component.ui.scrollpane.MovieSearchResultTableScrollPane;
import jym.tan.movielibrary.component.ui.splitpane.SingleMovieAddSplitPane;
import jym.tan.movielibrary.component.ui.table.LibraryTable;
import jym.tan.movielibrary.component.ui.table.MovieSearchResultTable;
import jym.tan.movielibrary.component.ui.table.model.LibraryTableModel;
import jym.tan.movielibrary.component.ui.textfield.AddSingleFolderTextField;
import jym.tan.movielibrary.component.ui.textfield.MovieTitleTextField;
import jym.tan.movielibrary.component.ui.toolbar.DefaultToolBar;
import jym.tan.movielibrary.constant.ComponentConstant;
import jym.tan.movielibrary.model.LibraryModel;

public final class ComponentFactory {
	private static LibraryFrame libraryFrame;
	
	private static LibraryTablePanel libraryTablePanel;
	private static AddSingleFolderButtonOuterPanel addSingleFolderButtonOuterPanel;
	private static AddSingleFolderTextFieldOuterPanel addSingleFolderTextFieldOuterPanel;
	private static SingleMovieAddPanel singleMovieAddPanel;
	private static MovieTitleConfirmPanel movieTitleConfirmPanel;
	private static SingleMovieAddUpperPanel singleMovieAddUpperPanel;
	private static SingleMovieAddLowerLeftPanel singleMovieAddLowerPanel;
	private static MovieSearchResultPanel movieSearchResultPanel;
	private static DefaultToolbarPanel defaultToolbarPanel;
	private static SingleMovieAddLowerRightPanel singleMovieAddLowerRightPanel;
	private static MovieSearchInfoPanel movieSearchInfoPanel;
	
	private static LibraryTableScrollPane libraryTableScrollPane;
	private static MovieSearchResultTableScrollPane movieSearchResultTableScrollPane;
	private static MovieSearchInfoScrollPane movieSearchInfoScrollPane;
	
	private static LibraryTable libraryTable;
	private static MovieSearchResultTable movieSearchResultTable;
	
	private static SingleMovieAddButton singleMovieAddButton;
	private static AddSingleFolderButton addSingleFolderButton;
	private static MovieTitleConfirmButton movieTitleConfirmButton;
	
	private static DefaultToolBar defaultToolBar;
	
	private static DefaultMenuBar defaultMenuBar;
	
	private static FileMenu fileMenu;
	
	private static SingleMovieAddMenuItem singleMovieAddMenuItem;
	private static RestartMenuItem restartMenuItem;
	
	private static SingleMovieAddDialog singleMovieAddDialog;
	private static MovieTitleConfirmDialog movieTitleConfirmDialog;
	
	private static SingleFolderChooser singleFolderChooser;
		
	private static AddSingleFolderTextField addSingleFolderTextField;
	private static MovieTitleTextField movieTitleTextField;
	
	private static FolderPathLabel folderPathLabel;
	private static MovieSearchPosterLabel movieSearchPosterLabel;
	private static MovieSearchNameLabel movieSearchNameLabel;
	private static MovieSearchYearLabel movieSearchYearLabel;
	private static IMDbLogoLabel imdbLogoLabel;
			
	private static ThemeComboBox themeComboBox;
	
	private static SingleMovieAddSplitPane singleMovieAddSplitPane;
	
			
	public static synchronized LibraryFrame getLibraryFrame() {
		if (libraryFrame == null) {
			libraryFrame = new LibraryFrame();
		}
		return libraryFrame;
	}

	public static synchronized LibraryTableScrollPane getLibraryTableScrollPane() {
		if (libraryTableScrollPane == null) {
			libraryTableScrollPane = new LibraryTableScrollPane();
		}
		return libraryTableScrollPane;
	}

	public static synchronized LibraryTablePanel getLibraryTablePanel() {
		if (libraryTablePanel == null) {
			libraryTablePanel = new LibraryTablePanel();
		}
		return libraryTablePanel;
	}

	public static synchronized LibraryTable getLibraryTable() {
		if (libraryTable == null) {
			TableModel model = new LibraryTableModel();
			ArrayList<LibraryModel> libraryModels = new ArrayList<LibraryModel>(0);
			((LibraryTableModel) model).setModels(libraryModels);
			libraryTable = new LibraryTable(model);
		}
		return libraryTable;
	}

	public static synchronized SingleMovieAddButton getSingleMovieAddButton() {
		if (singleMovieAddButton == null) {
			singleMovieAddButton = new SingleMovieAddButton();
		}
		return singleMovieAddButton;
	}

	public static synchronized DefaultToolBar getDefaultToolBar() {
		if (defaultToolBar == null) {
			defaultToolBar = new DefaultToolBar();
		}
		return defaultToolBar;
	}

	public static synchronized DefaultMenuBar getDefaultMenuBar() {
		if (defaultMenuBar == null) {
			defaultMenuBar = new DefaultMenuBar();
		}
		return defaultMenuBar;
	}

	public static synchronized SingleMovieAddMenuItem getSingleMovieAddMenuItem() {
		if (singleMovieAddMenuItem == null) {
			singleMovieAddMenuItem = new SingleMovieAddMenuItem();
		}
		return singleMovieAddMenuItem;
	}

	public static synchronized SingleMovieAddDialog getSingleMovieAddDialog() {
		if (singleMovieAddDialog == null) {
			singleMovieAddDialog = new SingleMovieAddDialog();
		}
		return singleMovieAddDialog;
	}

	public static synchronized SingleMovieAddPanel getSingleMovieAddPanel() {
		if (singleMovieAddPanel == null) {
			singleMovieAddPanel = new SingleMovieAddPanel();
		}
		return singleMovieAddPanel;
	}

	public static synchronized AddSingleFolderButton getAddSingleFolderButton() {
		if (addSingleFolderButton == null) {
			addSingleFolderButton = new AddSingleFolderButton();
		}
		return addSingleFolderButton;
	}

	public static synchronized SingleFolderChooser getSingleFolderChooser() {
		if (singleFolderChooser == null) {
			singleFolderChooser = new SingleFolderChooser();
		}
		return singleFolderChooser;
	}

	public static synchronized AddSingleFolderButtonOuterPanel getAddSingleFolderButtonOuterPanel() {
		if (addSingleFolderButtonOuterPanel == null) {
			addSingleFolderButtonOuterPanel = new AddSingleFolderButtonOuterPanel();
		}
		return addSingleFolderButtonOuterPanel;
	}

	public static synchronized AddSingleFolderTextField getAddSingleFolderTextField() {
		if (addSingleFolderTextField == null) {
			addSingleFolderTextField = new AddSingleFolderTextField();
		}
		return addSingleFolderTextField;
	}

	public static synchronized AddSingleFolderTextFieldOuterPanel getAddSingleFolderTextFieldOuterPanel() {
		if (addSingleFolderTextFieldOuterPanel == null) {
			addSingleFolderTextFieldOuterPanel = new AddSingleFolderTextFieldOuterPanel();
		}
		return addSingleFolderTextFieldOuterPanel;
	}

	public static synchronized FolderPathLabel getFolderPathLabel() {
		if (folderPathLabel == null) {
			folderPathLabel = new FolderPathLabel();
		}
		return folderPathLabel;
	}

	public static synchronized MovieTitleConfirmButton getMovieTitleConfirmButton() {
		if (movieTitleConfirmButton == null) {
			movieTitleConfirmButton = new MovieTitleConfirmButton();
		}
		return movieTitleConfirmButton;
	}

	public static synchronized MovieTitleTextField getMovieTitleTextField() {
		if (movieTitleTextField == null) {
			movieTitleTextField = new MovieTitleTextField();
		}
		return movieTitleTextField;
	}

	public static synchronized MovieTitleConfirmPanel getMovieTitleConfirmPanel() {
		if (movieTitleConfirmPanel == null) {
			movieTitleConfirmPanel = new MovieTitleConfirmPanel();
		}
		return movieTitleConfirmPanel;
	}

	public static synchronized MovieTitleConfirmDialog getMovieTitleConfirmDialog() {
		if (movieTitleConfirmDialog == null) {
			movieTitleConfirmDialog = new MovieTitleConfirmDialog();
		}
		return movieTitleConfirmDialog;
	}

	public static synchronized SingleMovieAddUpperPanel getSingleMovieAddUpperPanel() {
		if (singleMovieAddUpperPanel == null) {
			singleMovieAddUpperPanel = new SingleMovieAddUpperPanel();
		}
		return singleMovieAddUpperPanel;
	}

	public static synchronized SingleMovieAddLowerLeftPanel getSingleMovieAddLowerLeftPanel() {
		if (singleMovieAddLowerPanel == null) {
			singleMovieAddLowerPanel = new SingleMovieAddLowerLeftPanel();
		}
		return singleMovieAddLowerPanel;
	}

	public static synchronized MovieSearchResultPanel getMovieSearchResultPanel() {
		if (movieSearchResultPanel == null) {
			movieSearchResultPanel = new MovieSearchResultPanel();
		}
		return movieSearchResultPanel;
	}

	public static synchronized MovieSearchResultTableScrollPane getMovieSearchResultTableScrollPane() {
		if (movieSearchResultTableScrollPane == null) {
			movieSearchResultTableScrollPane = new MovieSearchResultTableScrollPane();
		}
		return movieSearchResultTableScrollPane;
	}

	public static synchronized MovieSearchResultTable getMovieSearchResultTable() {
		if (movieSearchResultTable == null) {
			movieSearchResultTable = new MovieSearchResultTable(ModelFactory.getMovieSearchResultTableModel());
		}
		return movieSearchResultTable;
	}

	public static synchronized ThemeComboBox getThemeComboBox() {
		if(themeComboBox == null) {
			themeComboBox = new ThemeComboBox(ModelFactory.getThemeComboBoxModel());
		}
		return themeComboBox;
	}

	public static synchronized DefaultToolbarPanel getDefaultToolbarPanel() {
		if(defaultToolbarPanel == null) {
			defaultToolbarPanel = new DefaultToolbarPanel();
		}
		return defaultToolbarPanel;
	}

	public static synchronized SingleMovieAddLowerRightPanel getSingleMovieAddLowerRightPanel() {
		if(singleMovieAddLowerRightPanel == null) {
			singleMovieAddLowerRightPanel = new SingleMovieAddLowerRightPanel();
		}
		return singleMovieAddLowerRightPanel;
	}

	public static synchronized MovieSearchInfoPanel getMovieSearchInfoPanel() {
		if(movieSearchInfoPanel == null) {
			movieSearchInfoPanel = new MovieSearchInfoPanel(ComponentConstant.Color.LIGHT_BLUY, ComponentConstant.Color.DARK_BLUE);
		}
		return movieSearchInfoPanel;
	}

	public static synchronized MovieSearchInfoScrollPane getMovieSearchInfoScrollPane() {
		if(movieSearchInfoScrollPane == null) {
			movieSearchInfoScrollPane = new MovieSearchInfoScrollPane();
		}
		return movieSearchInfoScrollPane;
	}

	public static synchronized RestartMenuItem getRestartMenuItem() {
		if(restartMenuItem == null) {
			restartMenuItem = new RestartMenuItem();
		}
		return restartMenuItem;
	}

	public static synchronized FileMenu getFileMenu() {
		if(fileMenu == null) {
			fileMenu = new FileMenu();
		}
		return fileMenu;
	}

	public static synchronized MovieSearchPosterLabel getMovieSearchPosterLabel() {
		if(movieSearchPosterLabel == null) {
			movieSearchPosterLabel = new MovieSearchPosterLabel();
		}
		return movieSearchPosterLabel;
	}

	public static synchronized MovieSearchNameLabel getMovieSearchNameLabel() {
		if(movieSearchNameLabel == null) {
			movieSearchNameLabel = new MovieSearchNameLabel(); 
		}
		return movieSearchNameLabel;
	}

	public static synchronized MovieSearchYearLabel getMovieSearchYearLabel() {
		if(movieSearchYearLabel == null) {
			movieSearchYearLabel = new MovieSearchYearLabel();
		}
		return movieSearchYearLabel;
	}

	public static synchronized IMDbLogoLabel getImdbLogoLabel() {
		if(imdbLogoLabel == null) {
			imdbLogoLabel = new IMDbLogoLabel();
		}
		return imdbLogoLabel;
	}

	public static synchronized SingleMovieAddSplitPane getSingleMovieAddSplitPane() {
		if(singleMovieAddSplitPane == null) {
			singleMovieAddSplitPane = new SingleMovieAddSplitPane();
		}
		return singleMovieAddSplitPane;
	}
}
